
var layer = layui.layer //弹层
    ,table = layui.table //表格
form = layui.form,$ = layui.jquery,lotNo = getQueryVariable("lotNo");
table.render({
    elem: '#product'
    ,url:'initStock/add/getProductInfoByPage'
    ,cols: [[
        {checkbox: true, sort: true,title:'选择'}
        ,{field:'productCode', width: 120, title:'产品编码', sort: true}
        ,{field:'specificationCode', width: 120, title:'规格编码', sort: true}
        ,{field:'productUnit',width: 120, title:'产品单位', sort: true}
        ,{field:'productCname', title:'产品中文名称', sort: true}
        ,{field:'productEname', title:'产品英文名称', sort: true}
        ,{field:'productCdesc', title:'产品中文描述', sort: true}
        ,{field:'productEdesc', title:'产品英文描述', sort: true}
        ,{field:'specificationExplanation', width: 120, title:'规格说明', sort: true}
        ,{field:'color', width: 120, title: '颜色', sort: true}
    ]]
    ,id: 'producttableid'
    ,page: true
    , parseData: function(res){
        return {
            "code": res.status,
            "count": res.total,
            "data": res.data
        };
    }
    ,height: 600
});
form.on('submit(submitform)', function(data){
    table.reload('producttableid', {
        page: {
            limit:10,
            curr: 1 //重新从第 1 页开始
        }
        ,where: data.field
    }, 'data');
    return false;
});

$("#choose").on("click",function () {
    let productData =   table.checkStatus("producttableid").data;
    if(productData.length == 0){
        layer.msg("请选择数据")
    }else{
        let oldData =  parent.table.cache["productinformationtableid"];
        let newData = [];
        let num = oldData.length+1;
        for(let i in productData){
            productData[i].tempId = num;
            productData[i].lotNo = lotNo;
            newData.push(productData[i]);
            num++;
        }
        oldData.push.apply(oldData, newData);
        parent.table.reload('productinformationtableid',{data : oldData});
        //执行接口
        layer.msg("保存成功", {icon: 6});
        setTimeout(function () {
            //保存成功则关闭此页面
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        },)
    }
})
$("#shutdown").on("click",function () {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
})

